<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="description" content="">
    <meta name="author" content="">
    <!--<link rel="icon" href="../../favicon.ico">-->

    <title>StegSolve</title>
    <link href="static/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
  </head>
  
  <body>
    <script src="static/jquery-2.1.4.min.js"></script>
    <script src="static/bootstrap-3.3.6/js/bootstrap.min.js"></script>
    <!--<script src="static/exif-js/exif.js"></script>-->
      
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">StegSolve</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            </ul>
        </div><!--/.nav-collapse -->
        </div>
    </nav>
      
    <div class="container">
        <div class="row">
            <canvas id="canvas" width="500" height="500">抱歉，您的浏览器还不支持canvas。</canvas>
        </div>
        <div class="row">
            <input type="file" id="imageFile" />
        </div>
        <div class="row" id="exif">
        </div>
    </div>
  </body>
  
  <script>
    var canvas = document.getElementById('canvas')
    var imageFile = document.getElementById('imageFile')

    
    imageFile.onchange =  function(event) {
      var selectedFile = event.target.files[0];
      var reader = new FileReader();
      reader.onload = putImage2Canvas;
      reader.readAsDataURL(selectedFile);
    }
    
    
    function putImage2Canvas(event) {
        var img = new Image();
        img.onload = function(){
            var AdjustRatio = canvas.width / img.width;
            if (canvas.height / img.height < AdjustRatio) {
                AdjustRatio = canvas.height / img.height
            } 
            
            canvas.height = img.height * AdjustRatio;
            canvas.width = img.width * AdjustRatio;
            var context = canvas.getContext('2d');
            context.drawImage(img, 0, 0, img.width * AdjustRatio, img.height * AdjustRatio);
            var imgdata = context.getImageData(0, 0, img.width, img.height);
            
            // EXIF.getData(img, function(){
            //     $('#exif').text(EXIF.pretty(this))
            // })

        }
        img.src = event.target.result;
    }
  </script>
  

</html>
